package pl.edu.mimuw.mas.editor.listener;

import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.widgets.Shell;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import pl.edu.mimuw.mas.chart.Chart;
import pl.edu.mimuw.mas.editor.MainEditorWindow;
import pl.edu.mimuw.mas.editor.NewChartDialog;

/**
 * Implementacja Listenera dla przycisku "new" w menu
 * aplikacji głównej.
 */
public class NewMenuItemListener implements SelectionListener {

	private final Logger log = LoggerFactory.getLogger(getClass());

	private final NewChartDialog dialog;
	private final MainEditorWindow main;
	
	public NewMenuItemListener(Shell shell, MainEditorWindow main) {
		this.dialog = new NewChartDialog(shell);
		this.main = main;
	}
	
	public void widgetSelected(SelectionEvent event) {
		log.debug("Wybrano");
		log.debug("Otwieram okno dialogowe");
		Object result = dialog.open();
		if (result != null && result instanceof Chart) {
			main.setChart((Chart) result);
		}
		log.debug("Włączam zapisywanie jako");
		main.enableSavingAs();
		log.debug("Wyłączam zapisywanie");
		main.disableSaving();
	}

	public void widgetDefaultSelected(SelectionEvent event) {
	}
}
